package com.sskj.gocoin.mine;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import com.luck.picture.lib.tools.Constant;
import com.sskj.common.util.LanguageUtil;
import com.sskj.gocoin.R;
import com.sskj.gocoin.R2;
import com.sskj.gocoin.common.widget.ToolBarLayout;
import com.sskj.gocoin.m.HttpConfig;
import com.sskj.gocoin.mine.data.BenefitBean;
import com.sskj.gocoin.p.base.BasePresenter;
import com.sskj.gocoin.utils.HtmlUtils;
import com.sskj.gocoin.v.base.BaseActivity;
import com.zzhoujay.richtext.RichText;

import butterknife.BindView;

public class GradeRuleActivity extends BaseActivity<GradeRulePresenter> {
    @BindView(R2.id.toolbar)
    ToolBarLayout toolbar;
    @BindView(R2.id.tv_grade_rule_gz)
    WebView tvGradeRule;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_grade_rule;
    }

    @Override
    public GradeRulePresenter getPresenter() {
        return new GradeRulePresenter();
    }

    @Override
    protected void initView() {
        super.initView();
        toolbar.setLeftButtonOnClickLinster(v -> finish());

        mPresenter.getBenefit();
    }

    public static void start(Context context) {
        Intent intent = new Intent(context, GradeRuleActivity.class);
        context.startActivity(intent);
    }

    public void onGetBenefit(BenefitBean benefitBean) {
        if (benefitBean != null) {
//            tvGradeRule.setText(benefitBean.getFygz());

            WebSettings settings = tvGradeRule.getSettings();
            settings.setJavaScriptEnabled(true);

//            settings.setJavaScriptCanOpenWindowsAutomatically(true);
//            settings.setUseWideViewPort(true);//关键点
//            settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
//            settings.setDisplayZoomControls(false);
//            settings.setJavaScriptEnabled(true);     // 设置支持javascript脚本
//            settings.setAllowFileAccess(true);       // 允许访问文件
//            settings.setSupportZoom(true);           // 支持缩放
//            settings.setLoadWithOverviewMode(true);

            tvGradeRule.setWebViewClient(new WebViewClient(){
                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    view.loadUrl(url);
                    return true;
                }
            });

            String data = "";
            if(LanguageUtil.isChinese()){
                data = benefitBean.getFygz();
            }else{
                data = benefitBean.getFygz1();
            }

//        webView.setFocusable(false);
            tvGradeRule.loadDataWithBaseURL(HttpConfig.BASE_URL, HtmlUtils.getHtmlData(data),"text/html; charset=UTF-8",null,null);
//            tvBenefitYh1.setText(benefitBean.getLvs().getFree_rate1()+"%");
//            tvBenefitYh2.setText(benefitBean.getLvs().getFree_rate2()+"%");
//            tvBenefitYh3.setText(benefitBean.getLvs().getFree_rate3()+"%");
//            tvBenefitGz1.setText(App.INSTANCE.getString(R.string.wyhl_dtqy) +benefitBean.getLvs().getLv1()+"USDT"+App.INSTANCE.getString(R.string.wyhl_ys));
//            tvBenefitGz2.setText(App.INSTANCE.getString(R.string.wyhl_dtqy)+benefitBean.getLvs().getLv2()+"USDT"+App.INSTANCE.getString(R.string.wyhl_ys));
//            tvBenefitGz3.setText(App.INSTANCE.getString(R.string.wyhl_dtqy)+benefitBean.getLvs().getLv3()+"USDT"+App.INSTANCE.getString(R.string.wyhl_ys));
        }
    }
}
